package com.elm.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.elm.po.Business;

@Mapper
public interface BusinessMapper {
	@Select("select * from business where order_type_id=#{orderTypeId}")
	List<Business> getBusinessByOrderTypeId(Integer orderTypeId);
	
	@Select("select * from business where id=#{businessId}")
	Business getBusinessById(Integer businessId);

	@Select("select * from business where business_status='opening' Order by monthly_sales DESC")
	List<Business> getBusinessBySales();

	@Select("select * from business where business_status='opening' Order by star DESC")
	List<Business> getBusinessByStar();

	@Select("select * from business where business_status='reviewing'")
	List<Business> getAllReviewingBusiness();
	
	@Insert("INSERT INTO business (" +
	        " creator,  " +
	        "business_address, business_explain, business_img, " +
	        "business_name, delivery_price, order_type_id, " +
	        "remarks, start_price, user_id, business_status" +
	        ") VALUES (" +
	        "#{creator}, " +
	        "#{businessAddress}, #{businessExplain}, #{businessImg}, " +
	        "#{businessName}, #{deliveryPrice}, 1, " +
	        "#{remarks}, #{startPrice}, #{userId}, 'reviewing'" +
	        ")")
	int createBusiness(Business business);

	@Update("update business set business_address=#{businessAddress},business_explain=#{businessExplain},business_img=#{businessImg},business_name=#{businessName},delivery_price=#{deliveryPrice},order_type_id=#{orderTypeId},"+
	"remarks=#{remarks},start_price=#{startPrice},business_status='reviewing' where id=#{id}")
	int updateBusiness(Business business);

	@Update("update business set business_status=#{business_status} where id=#{businessId}")
	int updateBusinessStatus(Integer businessId, String business_status);

	@Select("select * from business where business_name=#{businessName}")
	Business getBusinessByName(String business_name);

	@Select("select * from business where user_id=#{userId}")
	List<Business> getBusinessListByUserId(int userId);

	@Select("select * from business where business_status='opening'")
	List<Business> getAllBusiness();
	
	
}
 